package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ZhwyNotice;
import com.ruoyi.service.IZhwyNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业主通知公告Controller
 * 
 * @author JunEr
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/hyj/yzgg")
public class ZhwyNoticeController extends BaseController
{
    @Autowired
    private IZhwyNoticeService zhwyNoticeService;

    /**
     * 查询业主通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('hyj:yzgg:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhwyNotice zhwyNotice)
    {
        startPage();
        List<ZhwyNotice> list = zhwyNoticeService.selectZhwyNoticeList(zhwyNotice);
        return getDataTable(list);
    }

    /**
     * 导出业主通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('hyj:yzgg:export')")
    @Log(title = "业主通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhwyNotice zhwyNotice)
    {
        List<ZhwyNotice> list = zhwyNoticeService.selectZhwyNoticeList(zhwyNotice);
        ExcelUtil<ZhwyNotice> util = new ExcelUtil<ZhwyNotice>(ZhwyNotice.class);
        util.exportExcel(response, list, "业主通知公告数据");
    }

    /**
     * 获取业主通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('hyj:yzgg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zhwyNoticeService.selectZhwyNoticeById(id));
    }

    /**
     * 新增业主通知公告
     */
    @PreAuthorize("@ss.hasPermi('hyj:yzgg:add')")
    @Log(title = "业主通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhwyNotice zhwyNotice)
    {
        return toAjax(zhwyNoticeService.insertZhwyNotice(zhwyNotice));
    }

    /**
     * 修改业主通知公告
     */
    @PreAuthorize("@ss.hasPermi('hyj:yzgg:edit')")
    @Log(title = "业主通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhwyNotice zhwyNotice)
    {
        return toAjax(zhwyNoticeService.updateZhwyNotice(zhwyNotice));
    }

    /**
     * 删除业主通知公告
     */
    @PreAuthorize("@ss.hasPermi('hyj:yzgg:remove')")
    @Log(title = "业主通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhwyNoticeService.deleteZhwyNoticeByIds(ids));
    }
}
